/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.registration;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @date May 10, 2012
 *
 * @author ggutierrez
 */
public class SearchManagedBean extends ManagedBean {

    private Collection results;
    private Object result;
    private Object criteria;
    private String criteriaClassname;

    /**
     * Creates a new instance of SearchWebBean
     */
    public SearchManagedBean() {
    }

    public void setCriteriaClassname(String criteriaClassname) {
        this.criteriaClassname = criteriaClassname;
    }

    public Object getCriteria() {
        if (criteria == null && criteriaClassname != null) {
            setup();
        }
        return criteria;
    }

    public Collection getResults() {
        return results;
    }

    public void setResults(Collection results) {
        if (results instanceof List || results == null) {
            this.results = results;
        } else {
            this.results = new ArrayList(results);
        }
    }

    public void setup() {
        try {
            Class clazz = Class.forName(criteriaClassname);
            criteria = clazz.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    public String startup() {
        setup();
        return "success";
    }

    public void search() {
    }

    @Override
    public void reset() {
        results = null;
    }

    @Override
    public String cancel() {
        results = null;
        return "cancel";
    }
}
